<?php
/*
 * employe/select-diplome.phtml
 */
?>
<?php
$diplomes	 = $this->diplomes;
$count		 = $this->count;
$matricule	 = $this->matricule;
?>

<div class="empl-border">
    <?php if ($count > 0): ?>
	<?php foreach ($diplomes as $d): ?>
	    <div class="empl-full vert-olive">
		<a href="#" class="select-diplome" data-diplome="<?php echo $d->id; ?>" data-matricule="<?php echo $matricule; ?>"><?php echo $d->libelle; ?></a>
	    </div>
	<?php endforeach; ?>
    <?php else: ?>
        <div class="empl-full bleu">Aucun Diplôme dans la base de données</div>
    <?php endif; ?>
    <div class="empl-full">
	&nbsp;<a href="<?php echo $this->url('RHX/default', array('controller'	 => 'diplome', 'action'	 => 'index')) ?>" target="_blank" class="btn btn-info close-after" style="float:right;">Aller à la gestion des diplomes &nbsp;&nbsp;<i class='icon-white icon-home'></i></a>
    </div>
</div>

<script type="text/javascript">
    // Démarrage
    $(function() {
	// Selection de diplome
	$('.select-diplome').click(function(e) {
	    e.preventDefault();
	    diplome = $(this).attr('data-diplome');
	    matricule = $(this).attr('data-matricule');
	    ajax = $.ajax({
		dataType: 'json',
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addDiplome')) ?>',
		data: '&diplome=' + diplome + '&matricule=' + matricule
	    });
	    ajax.done(function(result) {
		if (result.etat) {
		    // Enregistrement réussie
		    d = result.diplome;
		    ed = result.employeDiplome;
		    diplomas = '<div  style="position: relative"><div class="empl-full violet" id="d' + ed.id + '">' + d.libelle + '</div><div class="cancel-icon"><a href="#" onclick=" return deleteSomething(\'<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'deleteDiplome')) ?>\', \'' + ed.id + '\', \'Voulez-vous effacer le diplome ?\', \'d\');" title="Effacer le Diplôme"><img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer le Diplôme"></a></div></div>';
					//diplomas = "<div class='empl-full violet' id='" + d.id + "'>" + d.libelle + "</div>" + effacer;
					$('#diplomes').hide().append(diplomas).fadeIn('normal');
					$('#diplome-none').hide('fast');
					$('#dialog1').dialog('close');
    <?php if ((int) $matricule == 0): ?>
            					$('#newEmploye').append("<input type='hidden' id='form-d" + ed.id + "' name='diplomes[]' value='" + result.diplome.id + "'>");
    <?php endif; ?>
				    }
				});
				ajax.fail(function() {
				});
			    });
			    $('.close-after').click(function(){
				$('#dialog1').dialog('close');
			    });
    });
</script>